<?php


namespace app\pxs\controller;


use app\common\service\ReportService;
use app\common\validate\ReportCreateValidate;
use think\Request;

class Report
{
    protected $report = "";

    public function __construct(ReportService $report)
    {
        $this->report = $report;
    }

    public function create(Request $request)
    {
        try {
            $data = $request->only(['name', 'phone', 'staff_no', 'chat_id','source_type']);
            $validate = new ReportCreateValidate();
            if (!$validate->check($request->param())) throw new \QyApiError($validate->getError());
            $bool = $this->report->create($data);
            if (!$bool) throw new \QyApiError("创建举报失败");
        } catch (\QyApiError $exception) {
            return failedJson($exception->getMessage());
        }
        return pxsSuccessJson("创建举报成功", $bool);
    }
}